| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include <sys/types.h> |
| 40 |
#include <sys/socket.h> |
| 41 |
#include <netinet/in.h> |
| 42 |
#include <arpa/inet.h> |
| 43 |
#include <unistd.h> |
| 44 |
typedef int SOCKET; |
| 45 |
typedef struct sockaddr_in SOCKADDR_IN; |
| 46 |
typedef struct sockaddr SOCKADDR; |
| 47 |
#include <stdio.h> |
| 48 |
#include <stdlib.h> |
| 49 |
#include <string.h> |
| 50 |
|
| 51 |
#include <errno.h> |
| 52 |
|
| 53 |
struct pprsipaor |
| 54 |
{ |
| 55 |
char username[200]; |
| 56 |
char datatype1[255]; |
| 57 |
char datatype2[255]; |
| 58 |
char datatype3[255]; |
| 59 |
int accounting; |
| 60 |
}; |
| 61 |
|
| 62 |
int main (int argc, char **argv) |
| 63 |
{ |
| 64 |
SOCKET sock; |
| 65 |
SOCKADDR_IN sin; |
| 66 |
struct pprsipaor pprsip; |
| 67 |
int numdatatype=0,i=0; |
| 68 |
int port=667; |
| 69 |
|
| 70 |
sock = socket(AF_INET, SOCK_STREAM, 0); |
| 71 |
sin.sin_addr.s_addr = inet_addr("127.0.0.1"); |
| 72 |
sin.sin_family = AF_INET; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
pprsip.username[0]='\0'; |
| 77 |
pprsip.datatype1[0]='\0'; |
| 78 |
pprsip.datatype2[0]='\0'; |
| 79 |
pprsip.datatype3[0]='\0'; |
| 80 |
pprsip.accounting=0; |
| 81 |
|
| 82 |
|
| 83 |
if(argc<3) |
| 84 |
{ |
| 85 |
fprintf(stderr,"Missing arguments! You must at least provide a username.\n"); |
| 86 |
return 1; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
for (i=1;i<argc;i++) |
| 91 |
{ |
| 92 |
|
| 93 |
if(strncmp(argv[i],"-",1)==0) |
| 94 |
{ |
| 95 |
if(strcmp(argv[i],"-u")==0) |
| 96 |
{ |
| 97 |
|
| 98 |
if(strlen(argv[i+1])<199) |
| 99 |
{ |
| 100 |
strcpy(pprsip.username,argv[i+1]); |
| 101 |
|
| 102 |
i++; |
| 103 |
} |
| 104 |
else |
| 105 |
{ |
| 106 |
fprintf(stderr,"Username is too long!\n"); |
| 107 |
} |
| 108 |
} |
| 109 |
else if(strcmp(argv[i],"-t")==0) |
| 110 |
{ |
| 111 |
i++; |
| 112 |
int j=i; |
| 113 |
|
| 114 |
for(j=i;j<argc;j++) |
| 115 |
{ |
| 116 |
|
| 117 |
if(strncmp(argv[i],"-",1)!=0) |
| 118 |
{ |
| 119 |
if(strlen(argv[i])>254) |
| 120 |
{ |
| 121 |
fprintf(stderr,"User-data type is too long!\n"); |
| 122 |
} |
| 123 |
else |
| 124 |
{ |
| 125 |
if(numdatatype<3) |
| 126 |
{ |
| 127 |
switch(numdatatype) |
| 128 |
{ |
| 129 |
case 0: |
| 130 |
strcpy(pprsip.datatype1,argv[i]); |
| 131 |
break; |
| 132 |
case 1: |
| 133 |
strcpy(pprsip.datatype2,argv[i]); |
| 134 |
break; |
| 135 |
case 2: |
| 136 |
strcpy(pprsip.datatype3,argv[i]); |
| 137 |
break; |
| 138 |
} |
| 139 |
numdatatype++; |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
fprintf(stderr,"You can not provide more than 3 User-data type at the same time!\n"); |
| 144 |
break; |
| 145 |
} |
| 146 |
} |
| 147 |
i=j+1; |
| 148 |
} |
| 149 |
else |
| 150 |
{ |
| 151 |
|
| 152 |
i--; |
| 153 |
break; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
else if(strcmp(argv[i],"-a")==0) |
| 158 |
{ |
| 159 |
pprsip.accounting=1; |
| 160 |
|
| 161 |
|
| 162 |
} |
| 163 |
else if(strcmp(argv[i],"-p")==0) |
| 164 |
{ |
| 165 |
|
| 166 |
if(sscanf(argv[i+1],"%d", &port)!=1) |
| 167 |
{ |
| 168 |
fprintf(stderr,"Incorrect port number!\n"); |
| 169 |
return 1; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
i++; |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
else |
| 178 |
{ |
| 179 |
fprintf(stderr,"Unknown argument: %s\n",argv[i]); |
| 180 |
i++; |
| 181 |
} |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
sin.sin_port = htons(port); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
if(strlen(pprsip.username)==0) |
| 191 |
{ |
| 192 |
fprintf(stderr,"You must provide a username!\n"); |
| 193 |
return 1; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
fprintf(stderr,"%d!\n",port); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin))) |
| 213 |
{ |
| 214 |
fprintf(stderr,"Connexion succeed!\n"); |
| 215 |
|
| 216 |
|
| 217 |
if(send(sock, &pprsip, sizeof(struct pprsipaor), 0)) |
| 218 |
fprintf(stderr,"sent OK!\n"); |
| 219 |
else |
| 220 |
fprintf(stderr,"not sent\n"); |
| 221 |
|
| 222 |
} |
| 223 |
else |
| 224 |
{ |
| 225 |
fprintf(stderr,"Unable to connect\n"); |
| 226 |
} |
| 227 |
|
| 228 |
close(sock); |
| 229 |
|
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|