Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Had to add something to tap.c

  • Loading branch information...
commit 01de8dbd655abf05b9cdf8f427b094e941c2f6b2 1 parent 4711efd
zoukai957 zoukai957 authored

Showing 1 changed file with 42 additions and 0 deletions. Show diff stats Hide diff stats

  1. +42 0 tap.c
42 tap.c
@@ -43,3 +43,45 @@ int allocate_tunnel(char *dev, int flags) {
43 43 strcpy(dev, ifr.ifr_name);
44 44 return fd;
45 45 }
  46 +
  47 +/**Continuously reads from the tap and prints the string it gets from tap
  48 + * Takes no parameters
  49 + * Will take up to 500 bytes from tap otherwise segmentation fault,
  50 + * but the 500 bytes is adjustable
  51 + * Exits entire program if for some reason program can't open tap*/
  52 +char * read(){
  53 + char *if_name = (char*)malloc(sizeof(char) * 16);
  54 + strcpy(if_name, "tap0");
  55 + int tap_fd;
  56 + //Malloc for the string that is taken from the tap (takes up to 500 bytes)
  57 + char *tapEntry = (char*)malloc(sizeof(char) * 500);
  58 +
  59 +
  60 + if ( (tap_fd = allocate_tunnel(if_name, IFF_TAP | IFF_NO_PI)) < 0 ) {
  61 + perror("Opening tap interface failed! \n");
  62 + exit(1);
  63 + }
  64 +
  65 + read(tap_fd, tapEntry,500);
  66 +
  67 + //free
  68 + free(tapEntry);
  69 +}
  70 +
  71 +/**Writes messages into the tap
  72 + * There are no parameters
  73 + Exits entire program if for some reason program can't open tap*/
  74 +char * write(char *msg){
  75 + char *if_name = (char*)malloc(sizeof(char) * 16);
  76 + strcpy(if_name, "tap0");
  77 + int tap_fd;
  78 +
  79 +
  80 + if ( (tap_fd = allocate_tunnel(if_name, IFF_TAP | IFF_NO_PI)) < 0 ) {
  81 + perror("Opening tap interface failed! \n");
  82 + exit(1);
  83 + }
  84 +
  85 + write(tap_fd, msg, sizeof(msg));
  86 +
  87 +}

0 comments on commit 01de8db

Please sign in to comment.
Something went wrong with that request. Please try again.