#include #include #include #include #include #include #include #include #include #include /*great = gre auto tunnel*/ int main(int argc,char *argv[]) { struct sockaddr_in sa; struct sockaddr_in from; char in; socklen_t sl=sizeof(struct sockaddr_in); int so_inet=socket(AF_INET,SOCK_DGRAM,0); int so=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); memset(&sa,0,(size_t)sizeof(struct sockaddr_in)); memset(&from,0,(size_t)sizeof(struct sockaddr_in)); if(argc < 4) { printf("usage: %s interface address port\n",argv[0]); printf("example: %s gre0 192.168.0.2 1013\n",argv[0]); return 1; } sa.sin_addr.s_addr=inet_addr(argv[2]); sa.sin_port=htons(atoi(argv[3])); sa.sin_family=PF_INET; bind(so,(struct sockaddr *)&sa,sizeof(sa)); recvfrom(so,&in,1,0,(struct sockaddr *)&from,&sl); struct in_addr addr = {from.sin_addr.s_addr}; printf("setting remote end to %s:%d\n",inet_ntoa(addr),ntohs(from.sin_port)); connect(so,(struct sockaddr *)&from,sl); struct ifreq *data; data=malloc(sizeof(struct ifreq)); memset(data,0,sizeof(struct ifreq)); strcpy(data->ifr_name,argv[1]); data->ifr_value=so; printf("gressock: %d\n",ioctl(so_inet,GRESSOCK,data));//set socket free(data); return 0; }