コード例 #1
0
ファイル: ethersend.c プロジェクト: whiteley/cs494-hw1
int main(int argc, char **argv) {
  if (argc != 3) {
    usage(argv[0]);
  }

  int count, i, netsum, total = 0;
  register int checksum = 0;

  unsigned char buf[MTU];
  unsigned char dst[MACLEN];
  unsigned char src[MACLEN];

  // parse destination and source mac addresses
  if (readmac(argv[1], dst) != 1 || readmac(argv[2], src) != 1) {
    perror("argument error");
    exit(EXIT_FAILURE);
  }

  while (!feof(stdin)) {
    // attempt to read a full payload
    count = fread(buf, sizeof(char), MTU, stdin);

    // error in input
    if (ferror(stdin)) {
      perror("read error");
      exit(EXIT_FAILURE);
    }

    // build and output frame
    frame(dst, src, count, buf);
    printf("\n");

    // accumulate checksum
    for (i = 0; i < sizeof(buf); i++) {
      checksum += buf[i];
    }

    // accumulate total bytes read
    total += count;
  }

  // convert byte order from checksum register
  netsum = htonl(checksum);
  // copy checksum into buffer
  memcpy(buf, &netsum, CHECKLEN);
  // fill buffer with 0s
  memset(buf + CHECKLEN, 0, MTU - CHECKLEN);
  // build and output checksum frame
  frame(dst, src, MTU, buf);
  printf("\n");

  exit(EXIT_SUCCESS);
}
コード例 #2
0
ファイル: netstuff.c プロジェクト: asdf-asdf/ipfire-2.x
char* find_nic4mac(char *findmac) {
	DIR *dir;
	struct dirent *dirzeiger;
	char temp[STRING_SIZE], temp2[STRING_SIZE];
        
	if((dir=opendir(SYSDIR)) == NULL) {
		fprintf(flog,"Fehler bei opendir (find_name4nic) ...\n");
		return NULL;
	}

	sprintf(temp, "");
	while((dirzeiger=readdir(dir)) != NULL) {
		if(*((*dirzeiger).d_name) != '.' & strcmp(((*dirzeiger).d_name), "lo") != 0) {
			sprintf(temp2, "%s", readmac((*dirzeiger).d_name) );
			if (strcmp(findmac, temp2) == 0) {
				sprintf(temp,"%s", (*dirzeiger).d_name);
				break;
			}
		}
	}

	if(closedir(dir) == -1) fprintf(flog,"Fehler beim schliessen von %s\n", SYSDIR);
	strcpy(g_temp, temp);
	return g_temp;
}