3 #include <netinet/in.h>
7 #include <sys/socket.h>
11 int parseparams(int argc, char *argv[], ulong *adres, uint *rport, uint *lport, uint *service)
16 if (argc<1) return 255;
24 fprintf(stderr,"Error: missing remote port!\n");
26 fprintf(stderr,"Usage: ident <xxx.xxx.xxx.xxx> <remote port> [local port] [ident port]\n");
34 if (c<65536 && *s>='0' && *s<='9') c=c*10+*s-'0';
37 fprintf(stderr,"Error: wrong ident port!\n");
48 if (c<65536 && *s>='0' && *s<='9') c=c*10+*s-'0';
51 fprintf(stderr,"Error: wrong local port!\n");
63 if (*s>='0' && *s<='9')
68 fprintf(stderr,"Error: wrong address!\n");
79 fprintf(stderr,"Error: wrong address!\n");
85 fprintf(stderr,"Error: wrong address!\n");
96 if (c<65536 && *s>='0' && *s<='9') c=c*10+*s-'0';
99 fprintf(stderr,"Error: wrong remote port!\n");
109 int main(int argc, char *argv[])
112 struct sockaddr_in addr;
116 uint rport, lport, service;
118 static const int val_one=1;
120 if (parseparams(argc,argv,&adres,&rport,&lport,&service)) return 3;
122 if (DBG) fprintf(stderr,"addr: %lX rport: %u lport: %u service: %i\n",adres,rport,lport,service);
124 addr.sin_family=AF_INET;
125 addr.sin_addr.s_addr=htonl(adres);
126 addr.sin_port=htons(service);
128 sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
129 setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,&val_one,sizeof(val_one));
134 fprintf(stderr,"socket: %i, errno: %i\n",sock,err);
138 fprintf(stderr,"Error: cannot create socket!\n");
142 count=connect(sock,(struct sockaddr*)&addr,sizeof(addr));
146 fprintf(stderr,"connect: %i, errno: %i\n",count,err);
151 fprintf(stderr,"Error: connection failed!\n");
155 count=snprintf(buf,sizeof(buf),"%d , %d\n",rport,lport);
156 if (count==-1) return 1;
157 if (write(sock,buf,count)!=count) return 2;
161 count=read(sock,buf,sizeof(buf)-1);
168 if (DBG) fprintf(stderr,"count = %d , errno = %d\n",count,errno);