Code Monkey home page Code Monkey logo

hands-on-network-programming-with-c's People

Contributors

abin-packt avatar codeplea avatar ellainyang avatar karunvarma avatar kirkster96 avatar poojaparvatkar avatar willmafh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hands-on-network-programming-with-c's Issues

Closing socket_listen if it socket returns < 0

Hi Lewis,

I'm running the UDP server code through Coverity analysis and it states then returning here:

if (!ISVALIDSOCKET(socket_listen)) {

means socket_listen leaks resources when it goes out of scope. If you try to CLOSESOCKET(socket_listen); there, then it complains (rightly so) that:

54      if (!ISVALIDSOCKET(socket_listen)) {
55        fprintf(stderr, "socket() failed. (%d)\n", GETSOCKETERRNO());
>>>     CID 364052:  Error handling issues  (NEGATIVE_RETURNS)
>>>     "socket_listen" is passed to a parameter that cannot be negative.
           return 1;

what is the recommended technique here to handle that?

ssh_download failed on Windows 10

when I run the "ssh_download.exe localhost 22 username" command in cmd.exe, I try to download the test.txt that I have created in advance. But ssh_scp_pull_request() failed. Then I try to use the absolute path, it still failed. I promise that the test.txt is existing in that path.
bug
bug1
bug2
I don't know the reason.

Chap02 - Time Server Bind failing

When I compile and run the code for time_server.c I get the following:

bind() failed. (98)
Configuring local address...
Creating socket...
Binding socket to local address...
[Finished in 0.0s with exit code 1]
[shell_cmd: gcc "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server.c" -o "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server" && "/home/chuck/ContEd/HOCN/SampleCode/chap02/time_server"]
[dir: /home/chuck/ContEd/HOCN/SampleCode/chap02]
[path: /home/chuck/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

Using perror for better error messages

Really, really enjoying your book. Big thanks!

However, doing this would have helped me as port 8080 is in use on my system:

fprintf(stderr, "bind() failed. (%d)\n", GETSOCKETERRNO());

making it or adding another line:

git diff
diff --git a/chap02/time_server.c b/chap02/time_server.c
index b3456cb..50c13f5 100644
--- a/chap02/time_server.c
+++ b/chap02/time_server.c
@@ -97,6 +97,7 @@ int main() {
     if (bind(socket_listen,
                 bind_address->ai_addr, bind_address->ai_addrlen)) {
         fprintf(stderr, "bind() failed. (%d)\n", GETSOCKETERRNO());
+        perror("bind() failed");
         return 1;
     }
     freeaddrinfo(bind_address);

which then helps me with:

./time_server 
Configuring local address...
Creating socket...
Binding socket to local address...
bind() failed. (98)
bind() failed: Address already in use

Thanks.

DNS domain name should not be longer than 253 characters

Hi!

I found I minor issue with information about domain name lengths in the book and it's reflected int the dns_query.c code from chapter 5.

Specifically, the book mentions:

It also checks that the hostname isn't more than 255
characters long. Hostnames longer than that aren't allowed by the DNS standard, and
checking it now ensures that we don't need to allocate too much memory.

Which is reflected in the code here:

if (strlen(argv[1]) > 255) {
fprintf(stderr, "Hostname too long.");
exit(1);
}

But the DNS specification mentions:

To simplify implementations, the total number of octets that represent a
domain name (i.e., the sum of all label octets and label lengths) is
limited to 255.

See https://datatracker.ietf.org/doc/html/rfc1034#section-3.1

That effectively limits readable ASCII domain names to only 253 characters (excluding the optional . at the end).

For example using the dns_query program from the book as such:
./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789a.xyz a

Leads to a response indicating a format error:

QR = 1 response
OPCODE = 0 standard
AA = 0 
TC = 0 
RD = 1 recursion desired
RCODE = 1 format error

That is a readable domain name of length 254, which is more than the allowed 253 readable characters. Encoded in the DNS binary format, the total number of octets that it's represented by is 256 which is more than the allowed 255.

So as expected trying with a domain name that's only 253 characters long works just fine (notice the second level domain name is changed from 123456789a to 123456789):

./dns_query 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.xyz a

QR = 1 response
OPCODE = 0 standard
AA = 0 
TC = 0 
RD = 1 recursion desired
RCODE = 0 success
QDCOUNT = 1
ANCOUNT = 1
NSCOUNT = 0
ARCOUNT = 0

Reference to a practical explanation: https://devblogs.microsoft.com/oldnewthing/?p=7873

P.S.: I'm not a complete newbie in network programming but I still found your book useful, and I quite like it as a reference material.

Testing STMP with port 25

I'm working through the SMTP code (chapter 8) under Ubuntu and I wanted to share a tip for folks who cannot use port 25 for whatever reason. Under Linux and MacOS you can set up a local mail server to test against. I found a gist on Github link that has step-by-step instructions for doing so. Not sure about Windows as I haven't worked in that OS for a long time.

setsockopt won't compile on VC++

The call to setsockopt won't compiler on VC++ compiler since (on Windows headers), setsockopt takes char* and not void*. It is true that MS header/implmenetation is faulty as it doesn't make sense to take char* - but the code won't compile.

int option = 0;
setsockopt(socket_listen, IPPROTO_IPV6, IPV6_V6ONLY,(void*)&option, sizeof(option));

The # will never be removed when parsing the path.

Shouldn't this be *p++, since you are checking if *p == 0 in the look directly below which will always be true since we're setting *p = 0 here, and the loop looking for the hash will never be executed as the while condition is satisfied already? I don' think the # will ever be found and nulled out of the path and therefore is sent to the server with the current code.

chpt09 tls_client.exe

I compile it and run it. when it run to _kbhit(), the function return false. Then it's cause program block in SSL_read().

Chapter 2: time_server.c

Hi codeplea,

I realized the following behavior: The server closes after connection of the client browser. Closing the browser on the local maschine
leads to the strange state, that the server cannot bind to the 8080 port. This I observed on my local Debian machines.
Is there maybe something not released in the example code. After some time the binding is again possible. I think this is reasoned by TIME_WAIT for old packages. But it needs really minutes that the 8080 port is available again. Is there a way
to programmatically avoid this wait cycle. Maybe to early asked -- started the book reading some minutes ago.

Thanks for info, Stephan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.