[c] ping 소스 중에서..

terry9c의 이미지

안녕하세요..

C로 구현된 ping 소스에서 궁금한 점이 있어 글 올립니다.

#define DEFDATALEN 56
#define MAXIPLEN 60
#define MAXICMPLEN 76

main()
{
.........
datalen = DEFDATALEN;
packlen = datalen + MAXIPLEN + MAXICMPLEN;
if ( (packet = (u_char *)malloc((u_int)packlen)) == NULL) {
fprintf(stderr, "malloc error\n");
exit(1);
..........
}

이런 식으로 구현이 되어 있는데 패킷사이즈에 대해 궁금합니다.

DEFDATALEN이 ICMP 헤더 뒤에 붙는 데이터 길이를 의미하는 것으로 알고 있습니다.

그런데 MAXICMPLEN에 이미 ICMP 헤더 뿐만 아니라 데이터까지 포함된 길이를 의미하는게 아닌가 해서요..

sendto()에서는 ICMP Echo request 메시지 크기만큼만 보낼 수 있는데 왜 패킷사이즈를 56+60+76 만큼 설정해 놓은건지

모르겠습니다.

dude7853의 이미지

참고하신 ping 소스가 어떤것인지 몰라서, 확인은 못해봤지만.

위의 코드를 보면 packlen은 malloc하는데 쓰입니다. 즉, packet의 크기를 나타내는 거죠. MAXIPLEN, MAXICMPLEN 처럼 MAX가 붙어있는 define으로 보아서는, 아마도 최대값으로 할당해놓고, 실제 sendto에는 필요한 만큼만 사용하려는 것으로 보입니다.

swunk의 이미지

MAXICMPLEN이 데이터 길이까지 포함하는게 아닌것 같습니다.
일단.

#define DEFDATALEN 56
#define MAXIPLEN 60
#define MAXICMPLEN 76
에서
IP 헤더는 최대 60바이트가 맞고요..
ICMP 같은 경우는 기본 헤더가 8바이트이고 타입과 코드에 따라서 뒤에 가변적인것으로 알고 있습니다.
(님께서는 타입과 코드에 따라서 붙는 내용들을 DEFDATALEN으로 생각 하시는것 같은데요...)
제 생각에는...
ping 패킷을 만들어서 보낼때에도 패킷의 사이즈를 수천바이트로 만들어서 보낼수도 있는 것으로 봐서...위의 소스 프로그램은 일단 디폴트 데이터 사이즈는 56바이트로 정해 놓은 것이 아닌가 하는 추측(?)을 해 봅니다.

bleu의 이미지

#define DEFDATALEN 56
이부분은 예전에 짜둔걸 잠시 봤는데 제가 짜둔거에도 56으로
되어 있더군요..
더미 데이터 사이즈인거 같은데...
왜 그렇게 보냈는지는 정확히..
아무튼 더미 데이터 사이즈인걸로 알고 있습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.