home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-A.06 / NETKIT-A / NetKit-A-0.06 / pidentd-2.2 / src / kernel / linux.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  1.3 KB  |  67 lines

  1. /*
  2. ** kernel/linux.c                   Linux 0.99.13q or later access functions
  3. **
  4. ** This program is in the public domain and may be used freely by anyone
  5. ** who wants to. 
  6. **
  7. ** Last update: 17 Nov 1993
  8. **
  9. ** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <sys/param.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <arpa/inet.h>
  18.  
  19. int k_open()
  20. {
  21.     return 0;
  22. }
  23.  
  24.  
  25. int k_getuid(struct in_addr *faddr, int fport,
  26.          struct in_addr *laddr, int lport,
  27.          int *uid)
  28. {
  29.     FILE *fp;
  30.     long dummy;
  31.     char buf[512];
  32.     struct in_addr myladdr, myraddr;
  33.     int mylport, myrport;
  34.  
  35.     fport = ntohs(fport);
  36.     lport = ntohs(lport);
  37.     
  38.     /*
  39.      ** Open the kernel memory device
  40.      */
  41.     if ((fp = fopen("/proc/net/tcp", "r"))==NULL)
  42.     {
  43.     return -1;
  44.     }
  45.     
  46.     /* eat header */
  47.     fgets(buf,sizeof(buf)-1,fp);
  48.     while (fgets(buf, sizeof(buf)-1, fp))
  49.     {
  50.     if (sscanf(buf,"%d: %lX:%x %lX:%x %x %lX:%lX %x:%lX %lx %d",
  51.            &dummy, &myladdr, &mylport, &myraddr, &myrport,
  52.            &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
  53.            uid) == 12)
  54.     {
  55.         if (myladdr.s_addr==laddr->s_addr && mylport==lport &&
  56.         myraddr.s_addr==faddr->s_addr && myrport==fport)
  57.         {
  58.         fclose(fp);
  59.         return 0;
  60.         }
  61.     }
  62.     }
  63.  
  64.     fclose(fp);
  65.     return -1;
  66. }
  67.