UDP connection between client and server not loading on my Mac - c

i use a Mac from programming in C through Xcode. The version is macOS Mojave 10.14.
The code i'm using has a client who asks for time and a server who replies giving him the current time printed through a UDP connection.
I use client 127.0.0.1 to launch client.
The code works perfectly on linux, but on Mac it just starts loading and never stop.
These are the codes.
UDP Client
https://github.com/lufth/UDPClientServer/blob/master/clientUDP
UDP Server
https://github.com/lufth/UDPClientServer/blob/master/serverUDP

In Mac OS, there are several security features in place which is different from a linux machine. Maybe you could check to ensure if your program is not hindered by these 2 security features
Code Signing
Sandbox
For the sandbox, you may check if your UDP client / server executable is attempting to read/write to a location which is outside its allowed locations.
Alternatively, you may also try to run your server and client as root too
sudo java client.java 1111

The address_len parameter to recvfrom is an in/out parameter, but in your server you are passing a pointer to an uninitialized variable, len.
(Also, it is probably a good idea to give your C source files names ending in .c.)

Related

Random Timeout TFTP using KSZ8863 and AT91RM9200

Newbie in the community, here. First of all, thanks for all the help in all these years i've been working on embedded development :D
I have a problem with an Atmel AT91RM9200 ARM microprocessor, connected via RMII to a Mikrel KSZ8863 ethernet physical interface. The ARM is loaded with U-Boot 1.1.2, which loads the Linux Kernel v2.4.27.
I manually added the code to interface U-Boot with the KSZ.
The problem is:
Using U-Boot, if I try to download something from my TFTP server (located in the same network), the connection sometimes has so many timeouts that the download fails, and sometimes has just 2 or 3 timeouts.
I checked the U-Boot FAQ page, and the most probable reason for the timeouts is a wrong speed configuration, which I double checked.
What could be the reason for the unreliability of my connection?
Thanks,
Loranzp.
Setup a minimalist network consistent of TFTP server, client and Sniffer (Wireshark in promiscuous mode) (if you use a switch it must have a repeater port where to connect the sniffer PC)
Next run traffic captures and analyze when and how the timeouts occur.
Consider:
TFTP BlockSize too big leading to mishandled IP fragmentation.
Server provides the packets too fast after REQ or ACK
Not correctly handling block number roll-over (only when handling big files)
etc

Getting MAC adds of machine in C with MacOS

I am dealing with socket programming with C language and Xcode. I can open socket, server and client. I need to learn my machine's Mac address and then, I will send Arp request for server machine.
Almost all examples had been written for linux. I need to solve it in Mac OS.
Currently, I am using these codes with opening two projects and they are able to communicate.
https://www.geeksforgeeks.org/socket-programming-cc/
Could you give some example or information about this problem?

Telnet command for embeded system C

I have an embedded system that is programed in C. I need to do the equivalent to the DOS command Telnet. The idea is to test if the remote host is up and running.
I would like to have some orientation here like:
Open source project that I can use as a guide line (C language)
Some documentation on what the Telnet command does (so I can
implement my own)
Thanks
Update: Thank you for your valuable comments
My system connects to a host via GPRS/Ethernet/dial up/Wifi (one of them). As a developer I check if the host is ok by using my windows laptop (with a Dial up modem, GPRS modem or whatever is needed) and running Telnet like this:
telnet 192.168.0.1 8000
(non real values)
If the host is ok I got the clean screen, otherwise I got an error. That's what I need to do in code, to be able to determine if the host is up and running by using a sort of DOS telnet client command in C.
This is done once, just to check communications, after this test is cleared the real info should be sent.

Using gethostbyname() function on an external device

I'm using the client server program in C language on a Linux OS. In a first step, I programmed the code on the same machine using "localhost". Therefore, for the client to get the server information, I would use
server = gethostbyname("localhost")
since both the client and the server are running on the same machine.
However, now I would like to connect to an external device (using ssh). The device's username is of the following type
user#foxboard1
Although, I am not sure how to use the gethostbyname() function in this instance. I have tried
server = gethostbyname("user#foxboard1")
but that doesn't seem to work.
Any help would be appreciated!
P.s, I cannot copy and paste the code since it's on a different machine
EDIT
Instead of retreiving information about an external device, I would like to connect to the device using its IP address (an ssh connection through the connect() function.
gethostbyname() and its replacement getaddrinfo() are supposed to transform a host name or strin representation of an IP address into a "usable" structure.
This works very well on things like localhost, www.google.com, 1.2.3.4 etc.
But if you have a username embedded in the string, you'll have to split them up.
Of course, you'll have to become aware what kind of connection you want to establish and what the username is useful for.
If, as it seems, you want to do a SSH connection, it is probably best to use popen() and alike functions to start an external ssh process.

How to get a more stable socket connection in Linux/C

I'm running a game website where users connect using an Adobe Flash client to a C server running on a Fedora Linux box.
Often users complain about disconnects. Usually they're "Connection reset by peer"-disconnects.
Is there any way to make the connection more stable or does it all depend on the route from the user host to my server?
One thing I tried is to make it more stable by sending PING in clear text every other minute to avoid timeout problems.
Anyone got more ideas?
You are not exhausting the number of socket/memory use/cpu that the server process is given on the server, are you?
Do check with ulimit.
Also, if possible try to trace the error message in the source code (when a RST packet is sent--), i.e. when a send() or accept() returns an error value. In such cases print a debug message into the logs; if you really fancy debugging it do a simulation of the server:
run it into debug mode on a separate machine (possibly a clone of the server)
simulate thousands of connection (or find a network harnessing program)
backtrace the call and/or sniff the connection
where are you running the server?
at home? at work? at a hosting facility?
this will make a very big difference.
Can you design your app to connect to two sockets on the server and then load balance or make it active/passive (or active/active)?
You can use SO_KEEPALIVE TCP socket option.

Resources