/* NetGenesis4 Connect Utility nwg4con.c Copyright(C) 1998-1999 M.Okamura */ #include #include #include #include #define IP "192.168.0.1" #define SERIAL 1 /* #define DISCONNECT */ #define BUFSIZE 256 #define PORT 4449 main() { int i,sd,ip[4]; struct sockaddr_in to; char buf[BUFSIZE]; int size; memset(buf,0,BUFSIZE); buf[ 1] = 0x02; buf[ 4] = 0x01; #ifndef DISCONNECT buf[ 5] = 0x6A + (SERIAL -1); #else buf[ 5] = 0x68 + (SERIAL -1); #endif buf[ 7] = 0x04; sscanf(IP, "%d.%d.%d.%d", &ip[0],&ip[1],&ip[2],&ip[3] ); for(i=0;i<4;i++) buf[16+i] = (char)ip[i]; size = 20; memset(&to, 0, sizeof(to)); to.sin_family = PF_INET; to.sin_port = htons(PORT); to.sin_addr.s_addr = inet_addr(IP); if( (sd=socket(PF_INET,SOCK_DGRAM,0))<0 ) { perror("socket()"); exit(1); } sendto( sd, buf, size, 0, (struct sockaddr *)&to, sizeof(to) ); memset( &to, 0, sizeof(to) ); getsockname( sd, (struct sockaddr *)&to, &size ); printf("send.(IP=%s port=%d)\n",IP,ntohs(to.sin_port)); close(sd); }