~iaz/+junk/connect

« back to all changes in this revision

Viewing changes to src/connect_api.c

  • Committer: ivan.a.zorin at gmail
  • Date: 2013-04-05 16:47:32 UTC
  • Revision ID: ivan.a.zorin@gmail.com-20130405164732-2boigwci1at6hwoa
libconnect: lib/platform: trying to implement packet_send for GNU/Linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
208
208
        return 0;
209
209
}
210
210
 
 
211
/* stand alone connect API based sample for sending packet using raw socket */
 
212
int demo_usrsend(const char *argv[])
 
213
{
 
214
        /* engine, interface, proto, rule */
 
215
        int s = cnct_packet_open(CNCT_PACKENGINE_USR, NULL, 0, NULL);
 
216
        int mtu = 1504;
 
217
        unsigned char *packet = (unsigned char *) malloc(mtu);
 
218
        if (!packet) {
 
219
                perror("malloc");
 
220
                return errno;
 
221
        }
 
222
        memset(packet, 0xFF, mtu);
 
223
        cnct_packet_send(s, packet, mtu);
 
224
        cnct_packet_close(s);
 
225
        return 0;
 
226
}
 
227
 
211
228
/* usage helper */
212
229
int usage(const char *name)
213
230
{
220
237
        printf("\t\tudpserver  port\n");
221
238
        printf("\t\tbpfdump\n");
222
239
        printf("\t\tusrdump\n");
 
240
        printf("\t\tusrsend\n");
223
241
        return 0;
224
242
}
225
243
 
251
269
                demo_bpfdump(argv);
252
270
        } else if (strcmp(argv[1], "usrdump") == 0) {
253
271
                demo_usrdump(argv);
 
272
        } else if (strcmp(argv[1], "usrsend") == 0) {
 
273
                demo_usrsend(argv);
254
274
        } else {
255
275
                return usage(argv[0]);
256
276
        }