int main(int argc, char *argv) { char *buffer = "In the UNIX environment a thread: \n" \ "Exists within a process and uses the process resources\n" \ "Has its own independent flow of control as long as its parent process exists and the OS supports it\n" \ "May share the process resources with other threads that act equally independently (and dependently)\n" \ "Dies if the parent process dies - or something similar\n"; packet_dump(buffer, strlen(buffer), 16); }
$ ./packet_dump [ 0] 49 6e 20 74 68 65 20 55-4e 49 58 20 65 6e 76 69 In the UNIX envi [ 1] 72 6f 6e 6d 65 6e 74 20-61 20 74 68 72 65 61 64 ronment a thread [ 2] 3a 20 0d 0a 45 78 69 73-74 73 20 77 69 74 68 69 : ..Exists withi [ 3] 6e 20 61 20 70 72 6f 63-65 73 73 20 61 6e 64 20 n a process and [ 4] 75 73 65 73 20 74 68 65-20 70 72 6f 63 65 73 73 uses the process [ 5] 20 72 65 73 6f 75 72 63-65 73 0d 0a 48 61 73 20 resources..Has [ 6] 69 74 73 20 6f 77 6e 20-69 6e 64 65 70 65 6e 64 its own independ [ 7] 65 6e 74 20 66 6c 6f 77-20 6f 66 20 63 6f 6e 74 ent flow of cont [ 8] 72 6f 6c 20 61 73 20 6c-6f 6e 67 20 61 73 20 69 rol as long as i [ 9] 74 73 20 70 61 72 65 6e-74 20 70 72 6f 63 65 73 ts parent proces [ 10] 73 20 65 78 69 73 74 73-20 61 6e 64 20 74 68 65 s exists and the [ 11] 20 4f 53 20 73 75 70 70-6f 72 74 73 20 69 74 0d OS supports it. [ 12] 0a 4d 61 79 20 73 68 61-72 65 20 74 68 65 20 70 .May share the p [ 13] 72 6f 63 65 73 73 20 72-65 73 6f 75 72 63 65 73 rocess resources [ 14] 20 77 69 74 68 20 6f 74-68 65 72 20 74 68 72 65 with other thre [ 15] 61 64 73 20 74 68 61 74-20 61 63 74 20 65 71 75 ads that act equ [ 16] 61 6c 6c 79 20 69 6e 64-65 70 65 6e 64 65 6e 74 ally independent [ 17] 6c 79 20 28 61 6e 64 20-64 65 70 65 6e 64 65 6e ly (and dependen [ 18] 74 6c 79 29 0d 0a 44 69-65 73 20 69 66 20 74 68 tly)..Dies if th [ 19] 65 20 70 61 72 65 6e 74-20 70 72 6f 63 65 73 73 e parent process [ 20] 20 64 69 65 73 20 2d 20-6f 72 20 73 6f 6d 65 74 dies - or somet [ 21] 68 69 6e 67 20 73 69 6d-69 6c 61 72 0d 0a hing similar.. $
#include <pthread.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> void packet_dump(char* buf, int size, int unit) { char tmp[150]; char msg[256]; int i, j, lno; j = 7; lno = 0; memset((tmp+0), 0x00, 150); for (i = 0; i < size; i++) { if((i%unit) == 0) memset((tmp+0), 0x20, ((unit*3)+unit+1+7+3)); if(j == 7) sprintf((tmp+0), "[%4d] ", lno); sprintf((tmp+j), "%02x", (unsigned char)*(buf+i)); tmp[j+2] = 0x20; if((unsigned char)*(buf+i) >= (unsigned char)0x20) tmp[(j/3)+(unit*3)+1+6] = *(buf+i); else tmp[(j/3)+(unit*3)+1+6] = '.'; j += 3; if((i%unit) == (unit-1)) { printf("%s\n", (tmp+0)); j = 7; ++lno; } else if((i%unit) == ((unit/2)-1)) tmp[j-1] = '-'; } if ((i % unit) != 0) { printf("%s\n", (tmp+0)); } }
Tag : app, Application, data, Linux, network, socket, unix
Tag : php, 관리, 리눅스, 보안, 서버, 유지
Tag : 비애, 스타크레프트, 유머, 조삼모삼, 패러디
Tag : 노벨 경제학상 수상자, 러셀 크로우, 뷰티풀마인드, 수학가, 존 네쉬
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define ERR_MSG "usage : move file1 file2\n"
int main(int argc ,char *argv[]){
if(argc != 3){
fprintf(stderr,"%s",ERR_MSG);
exit(1);
}
else{
if(link(argv[1],argv[2])==-1){
perror("LINK ERROR :");
exit(1);
}
if(unlink(argv[1])==-1){
perror("UNLINK_ERR : REMOVE FILE IMPOSBLE");
exit(1);
}
printf("SUCCESS MOVE : %s -> %s",argv[1],argv[2]);
exit(0);
}
return 0;
}
Tag : instruction, Linux, move, mv, unix, 기초, 명령어
void PrintNetData(FILE * fp, u_char * start, const int len)
{
char *end; /* ptr to buffer end */
int i; /* counter */
int j; /* counter */
int dbuf_size; /* data buffer size */
int done; /* flag */
char *data; /* index pointer */
char *frame_ptr; /* we use 66 byte frames for a printed line */
char *d_ptr; /* data pointer into the frame */
char *c_ptr; /* char pointer into the frame */
char conv[] = "0123456789ABCDEF"; /* xlation lookup table */
/* initialization */
done = 0;
/* zero, print a <CR> and get out */
if(!len)
{
fputc('\n', fp);
return;
}
if(start == NULL)
{
printf("Got NULL ptr in PrintNetData()\n");
return;
}
end = (char*) (start + (len - 1)); /* set the end of buffer ptr */
if(len > IP_MAXPACKET)
{
if(pv.verbose_flag)
{
printf("Got bogus buffer length (%d) for PrintNetData, defaulting to 16 bytes!\n", len);
}
if(pv.verbose_bytedump_flag == 1)
{
dbuf_size = (FRAME_SIZE + 8) + (FRAME_SIZE + 8) + 1;
}
else
{
dbuf_size = FRAME_SIZE + FRAME_SIZE + 1;
}
/* dbuf_size = 66 + 67; */
end = (char*) (start + 15);
}
else
{
if(pv.verbose_bytedump_flag == 1)
{
/* figure out how big the printout data buffer has to be */
dbuf_size = ((len / 16) * (FRAME_SIZE + 8)) + (FRAME_SIZE + 8) + 1;
}
else
{
/* figure out how big the printout data buffer has to be */
dbuf_size = ((len / 16) * FRAME_SIZE) + FRAME_SIZE + 1;
}
/* dbuf_size = ((len / 16) * 66) + 67; */
}
/* generate the buffer */
//data_dump_buffer = (char *) malloc(dbuf_size);
if (data_dump_buffer == NULL)
{
AllocDumpBuf();
}
/* clean it out */
memset(data_dump_buffer, 0x20, dbuf_size);
/* set the byte buffer pointer to step thru the data buffer */
data = (char*) start;
/* set the frame pointer to the start of the printout buffer */
frame_ptr = data_dump_buffer;
/* initialize counters and frame index pointers */
i = 0;
j = 0;
/* loop thru the whole buffer */
while(!done)
{
if(pv.verbose_bytedump_flag == 1)
{
d_ptr = frame_ptr + 8;
c_ptr = (frame_ptr + 8 + C_OFFSET);
sprintf(frame_ptr, "0x%04X: ", j);
j += 16;
}
else
{
d_ptr = frame_ptr;
c_ptr = (frame_ptr + C_OFFSET);
}
/* process 16 bytes per frame */
for(i = 0; i < 16; i++)
{
/*
* look up the ASCII value of the first nybble of the current
* data buffer
*/
*d_ptr = conv[((*data & 0xFF) >> 4)];
d_ptr++;
/* look up the second nybble */
*d_ptr = conv[((*data & 0xFF) & 0x0F)];
d_ptr++;
/* put a space in between */
*d_ptr = 0x20;
d_ptr++;
/* print out the char equivalent */
if(*data > 0x1F && *data < 0x7F)
*c_ptr = (char) (*data & 0xFF);
else
*c_ptr = 0x2E;
c_ptr++;
/* increment the pointer or finish up */
if(data < end)
data++;
else
{
*c_ptr = '\n';
c_ptr++;
*c_ptr = '\n';
c_ptr++;
*c_ptr = 0;
dump_size = (int) (c_ptr - data_dump_buffer);
fwrite(data_dump_buffer, dump_size, 1, fp);
//ClearDumpBuf();
return;
}
}
*c_ptr = '\n';
if(pv.verbose_bytedump_flag == 1)
{
frame_ptr += (FRAME_SIZE + 8);
}
else
{
frame_ptr += FRAME_SIZE;
}
}
//ClearDumpBuf();
}
void PrintCharData(FILE * fp, char *data, int data_len)
{
int bytes_processed; /* count of bytes in the data buffer
* processed so far */
int linecount = 0; /* number of lines in this dump */
char *index; /* index pointer into the data buffer */
char *ddb_ptr; /* index pointer into the data_dump_buffer */
int size;
/* if there's no data, return */
if(data == NULL)
{
return;
}
/* setup the pointers and counters */
bytes_processed = data_len;
index = data;
/* allocate a buffer to print the data to */
//data_dump_buffer = (char *) calloc(data_len + (data_len >> 6) + 2, sizeof(char));
if (data_dump_buffer == NULL)
{
AllocDumpBuf();
}
size = (data_len + (data_len >> 6) + 2) * sizeof(char);
/* Based on data_len < 65535, this should never happen, but check just in
* case sizeof(char) is big or something. */
if (data_dump_buffer_size < size)
{
data_dump_buffer_size = size;
ClearDumpBuf();
/* Reallocate for a bigger size. */
AllocDumpBuf();
}
/* clean it out */
memset(data_dump_buffer, 0x20, size);
ddb_ptr = data_dump_buffer;
/* loop thru the bytes in the data buffer */
while(bytes_processed)
{
if(*index > 0x1F && *index < 0x7F)
{
*ddb_ptr = *index;
}
else
{
*ddb_ptr = '.';
}
if(++linecount == 64)
{
ddb_ptr++;
*ddb_ptr = '\n';
linecount = 0;
}
ddb_ptr++;
index++;
bytes_processed--;
}
/* slam a \n on the back */
ddb_ptr++;
*ddb_ptr = '\n';
ddb_ptr++;
/* setup the globals */
dump_size = (int) (ddb_ptr - data_dump_buffer);
fwrite(data_dump_buffer, dump_size, 1, fp);
//ClearDumpBuf();
}
Tag : Analysis, data, packet, Security!, snort, 보안
#include <sys/types.h> #include <sys/socket.h> int socket(int domain, int type, int protocol); |
통신을 위한 종점(endpoint)를 생성하기 위해서 사용한다. 성공적으로 함수를 수행했을경우, 통신 종점으로 사용될 파일 지시자를 리턴한다.
socket() 를 통해서 만들어진 파일 지시자는 보통 클라이언트의 연결을 듣기 위해서 사용됨으로 "듣기 소켓" 이라고 불리우기도 한다.
domain(도메인) 은 통신 도메인(영역)을 지정하기 위해서 사용한다.
유닉스 도메인 소켓으로 IPC 용으로 사용한다.
TCP/IP 프로토콜을 이용한 일반적인 인터넷 통신용으로 주로 사용된다. AF_UNIX 와 함께 가장 일반적으로 사용된다.
노벨의 IPX 프로토콜의 사용을 위해서 사용한다.
X.25 프로토콜
아마추어 라디오 X.25
type 은 통신에 사용될 패킷의 타입을 지정하기 위해서 사용한다.
연결지향의 TCP 프로토콜
데이타그램 지향의 UDP 프로토콜
생소켓 혹은 날소켓으로 불리우는 저수준 socket 제어 프로토콜
protocol 은 소켓을 사용하기 위한 프로토콜 지정을 위해 사용한다.
지정된 프로토콜 타입 혹은 프로토콜이 해당 도메인에서 지원되지 않을경우
새로운 소켓구조를 지정하기 위해 커널 메모리가 부족
프로세스 파일 테이블이 overflow
지정된 타입의 생성된 소켓이나 프로토콜 권한이 거부되었을경우, 대표적으로 RAW 소켓은 root 권한이 있어야 생성가능하다.
알려지지 않은 프로토콜을 사용했을 경우
#include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { int server_sockfd, client_sockfd; int state, client_len; struct sockaddr_in clientaddr, serveraddr, myaddr; // internet 기반의 스트림 소켓을 만들도록 한다. // server_sockfd 는 endpoint 소켓(듣기 소켓) 으로 사용된다. if ((server_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket error : "); exit(0); } bzero(&serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); serveraddr.sin_port = htons(12345); // 듣기 소켓에 소켓특성(주소, 포트)를 묶어준다. state = bind(server_sockfd , (struct sockaddr *)&serveraddr, sizeof(serveraddr)); if (state == -1) { perror("bind error : "); exit(0); } state = listen(server_sockfd, 5); if (state == -1) { perror("listen error : "); exit(0); } // 만약 듣기 소켓으로 클라이언트 연결이 들어왔다면, // 새로운 클라이언트와의 통신을 위한 소켓 지정번호를 할당한다. client_sockfd = accept(server_sockfd, (struct sockaddr *)&clientaddr, &client_len); if (client_sockfd == -1) { perror("Accept error : "); exit(0); } // 여기에서 부터는 클라이언트와의 통신 // ..... // ..... close(client_sockfd); return 1; } |
Tag : network, socket, system library
#include <sys/types.h>
#include <sys/socket.h>
int sendto(int s, const void *msg, size_t len, int flags,
const struct sockaddr *to, socklen_t tolen);
|
이함수는 다른 소켓으로 메시지를 보내기 위해서 사용된다. 이 함수는 연결지향소켓(TCP)과 그렇지않은 소켓타입(UDP) 모두에 사용가능하다.
s는 메시지를 보내고자 하는 소켓의 지정자이다.
msg는 보내고자 하는 메시지이며, len는 메시지의 길이이다.
to는 보내고자하는 곳의 주소정보를 가지고 있다. 사실 연결지향이라면 연결된 소켓을 통해서 그냥 쓰기만 하면 됨으로 이 정보는 필요없다(NULL), 그러나 연결지향이 아닌 UDP와 같은 연결일경우 주소구조체를 채워주어야만 제대로 메시지가 전달될 것이다. tolen는 sockaddr 구조체의 크기이다.
flags는 다음중 선택해서 지정할수 있다.
oub-of-band data를 이 개념을 지원하는 소켓으로 보낸다.
패킷을 전송하는데 게이트웨이를 사용하지 않고 직접 연결된 네트워크를 통해서 호스트로 보낸다. 이것은 diagnostic 혹은 routing 프로그램에 의해서만 사용한다.
non-blocking을 가능하게 한다.
다른 한쪽의 소켓의 연결이 끊겼을때, 소켓으로부터 발생하는 스트림상의 SIGPIPE를 보내지 않도록 요구한다. 그러나 EPIPE에러는 여전히 반환된다.
s 가 유효한 기술자가 아니다.
s 가 소켓이 아닌 파일일경우
실제하지 않는 사용자 공간주소가 매개변수로 지정되었다.
신호발생으로 인하여 인터럽트가 걸렸다.
연결된 소켓이 깨졌다. MSG_NOSIGNAL이 설정되어 있지 않을경우 프로세스는 SIGPIPE신호를 받게 된다.
#include <sys/socket.h> #include <sys/stat.h> #include <arpa/inet.h> #include <stdio.h> #include <string.h> int main(int argc, char **argv) { int server_sockfd, client_sockfd; int client_len, n; char buf[80]; struct sockaddr_in clientaddr, serveraddr; client_len = sizeof(clientaddr); if ((server_sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket error : "); exit(0); } bzero(&serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); serveraddr.sin_port = htons(atoi(argv[1])); bind (server_sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); listen(server_sockfd, 5); while(1) { memset(buf, 0x00, 80); client_sockfd = accept(server_sockfd, (struct sockaddr *)&clientaddr, &client_len); if ((n = read(client_sockfd, buf, 80)) <= 0) { close(client_sockfd); continue; } sendto(client_sockfd,(void *)buf, 80, 0, NULL, client_len); close(client_sockfd); } } |
Tag : network, sendto, socket, system library, TCP/IP, udp
|
페라리 599 GTB 피오라노 | |
| 가격 | 2억 4천 974만원(유로) |
| 엔진 |
V12, 48밸브, DOHC 5999cc |
| 변속기 | 6단 자동 |
| 사이즈 | 4665x1962x1336mm |
| 휠 베이스 | 2750mm |
| 총 중량 | 1688kg |
| 출력 | 620ps/7600rpm |
| 토크 | 62.0kg-m/5600rpm |
| 0-100km | 3.7초 |
| 최대 시속 | 330km |
| 구동 | FR |
| 연비 | 21.3L/100km |
| * 제원은 참고사항으로써, 실제 차량과 다를수 있습니다. | |
|---|---|
Tag : FERRARI 599 GTB FIORANO, 페라리