Supprimer un message
philfr
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
FILE *fp;
char buffer[80];
int n, la, lp, ra, rp;
int ret;
int port;
struct in_addr radd;
if(argc != 2)
{
fprintf(stderr, "Usage %s <local port number>\n", argv[0]);
exit(1);
}
port=strtol(argv[1], NULL, 0);
fp=fopen("/proc/net/tcp", "r");
while(!feof(fp))
{
fgets(buffer, sizeof(buffer), fp);
ret=sscanf(buffer, "%d: %x:%x %x:%x", &n, &la, &lp, &ra, &rp);
if(ret==5)
{
if(lp==port)
{
radd.s_addr=ra;
printf("Remote address %s, remote port %d\n", inet_ntoa(radd), rp);
}
}
}
}