?? libcommon.c
字號:
/*
* libcommon.c
* CS 3251 Project 2
* Andrew Trusty
*
* Licensed under the
* Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
* For details of this license see:
* http://creativecommons.org/licenses/by-nc-sa/2.5/
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#//include <sys/types.h>
#include <winsock.h>
//#include <netinet/in.h>
//#include <arpa/inet.h>
#include "libcommon.h"
#include "dropper.h"
/* the debug flag all other files reference */
int debug = 0;
extern int sock;
extern FILE *fp;
/* handle interrupt signals */
void sigint() {
eprint("caught SIGINT, terminating...\n");
if (NULL != fp) fclose(fp);
sclose(sock);
exit(0);
}
/* set the debug flag according to command line arguments and
shift down the other arguments overwriting the debug argument */
void setDebug(int *argc, char* argv[]) {
if (*argc > 1) { /* debug is the only supported extra parameter */
int i;
for (i = 1; i < *argc; i++) {
if (strncmp(argv[i], "-d", 2) == 0) {
debug = 1;
break;
}
}
/* move other parameters down in array */
if (debug) {
for (; i < *argc; i++)
if (i < (*argc)-1)
argv[i] = argv[i+1];
(*argc)--;
}
}
}
/*
given the type of socket, creates a socket and
returns the socket handler
*/
int createUDPsocket() {
int sock, socktype;
socktype = SOCK_DGRAM;
if (-1 == (sock = socket(PF_INET, socktype, IPPROTO_UDP))) {
eprint("socket creation failed!\n");
exit(-1);
}
print("created socket\n");
return sock;
}
/* close the given socket if it is open */
void sclose(int sock) {
if (-1 == sock) return;
if (-1 == close(sock)) {
eprint("error closing socket! \n");
exit(-1);
}
print("closed socket\n");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -