Getting MAC adds of machine in C with MacOS - c

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?

Related

UDP connection between client and server not loading on my Mac

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.)

connection between windows and Linux sockets in c

I am using the socket module in python to send commands to my raspberry pi to turn GPIO pins on and of.
I am switching to C, where I will use winsock.h and winsock2.h to create the server on my PC and sys/socket.h to create a client on the raspberry pi.
Is it possible to establish a connection between these two different libraries?
I only want to create a socket, bind, send and recv. No other operations.
I recommend you to check this documentation, there are some examples for a Windows Server / Client connection:
https://learn.microsoft.com/en-us/windows/win32/winsock/getting-started-with-winsock
For Linux you need to do some adaptations as you might know or you have already implemented, I did the same for 2 desktop applications to send data from a Linux PC (client) to a Windows PC (server). As mentioned in the comments it doesn't matter the devices while they are in the same network and follow the TCP/IP protocol.
I was able to do this even connected through a VPN. Unfortunatelly I can not share the code. But I developed this communication based on the documentation from the link above.
I hope it helps. Actually if you want to use Python in the raspberry Pi there is also a python built-in package that you could use: https://docs.python.org/3/library/socket.html
And you can use the code from the link above in Windows. It should be straighforward.

Difference between programming on an embedded device with OS vs. no OS

I've recently programmed a client server program in C where the server was running on an embedded board that had a Linux OS and the client was running on a Linux machine. All I had to do was specify the board's IP address to the client running on the machine to establish a connection.
But now I'm doing essentially the same thing but the server is running on an embedded board that has no OS. I'm still establishing a tcp/ip connection between the server and the client, but I'm using a standard library called uIP (microIP).
I was told that the code that would run on the embedded board (the server) would be very tricky to write since it would have to be platform specific, i.e I'd be better off getting a code that was already intented for the platform. My question is though: why is it that much harder to program a C file on a board to establish a connection when the board has no OS, when it was relitavely "easy" to do so on the board with an OS. All I did for the latter was write the code on the Linux machine, then transfer the code on the OS board with scp, compile it, and execute it. Why can't the same be done for the OS'less board? I know I wouldn't be able to compile on the board, but can't I cross compile the server on a machine, and load it onto the board without having to worry about anything else? Why is this circumstance so much more complicated than if I were working with an OS board?
The uIP library most likely implements just the TCP stack. It still needs a way to talk to the hardware. This is what OS is for. Setting up DMA, managing buffers, serving interrupts (and interacting mainline code with ISRs).
With no OS you'd have to implement everything manually.

Basic hello world program using uIP library on embedded board

I am currently working with an embedded FOX G20 V board with an ATMEL AT91SAM9G20 processor. I am hoping to be able to establish a connection by ethernet between this board, and a linux machine. The protocol of communication is using the uIP library (smaller implementation of TCP/IP intended for embedded boards).
Anyway, I've downloaded the developpment kit offered by the processor, and it has countless examples of different types of communications, one of which includes a hello world program.
However, at this point, even with the example, I'm relitvely stuck. I am un sure which file of the hello world project it is I have to compile since there are many of them. Is it the main.c that is located in at91sam9g20-ek.zip\at91sam9g20-ek\packages\basic-emac-uip-helloworld-project-at91sam9g20-ek-iar.zip\basic-emac-uip-helloworld-project-at91sam9g20-ek\at91sam9g20-ek\basic-emac-uip-helloworld-project\ or is it another file?
The whole point is to get a communication established by the board and the remote host (in this case my Linux machine), and send it "hello world" through ethernet. I am guessing that the application in this case defines its register addresses in which the board will be able to receive the connection from the remote host (I may be wrong).
In any case, I am hoping to get help by any "experts" that are familier with the project that may guide me, or explain to me how exactly to build this application they have provided.
I'm not familiar with this board but according to this link the application is supposed to start a telnet server (on port 1000) and an http server. I suggest that you look at the output on the serial link (to get the IP of your board, let's assume 10.159.245.156 as in the example), and if you get what is expected then you can try to telnet to your board:
telnet 10.159.245.156 1000
The kit gives you project file for three toolchains (IAR 5.4, Keil and GNU). You'll have either to open the correct one depending on your toolchain (which one do you use?), or adapt if you use another one.
Edit: You apparently use the IAR toolchain, thus you need to open the *.eww file (for instance basic-emac-uip-helloworld-project.eww). This example only obtains an IP and displays statistics on the debug output (serial link?). There are other examples for a telnet or http server.
Moreover it's a detail but I think the emacs tag is irrelevant in your post. I think you confused EMAC (what is this?) and Emacs which is a popular text editor.

l2cap server/client using IOBluetooth (osx bluetooth stack)

I'm having trouble understanding the API to set up a l2cap (or RFCOMM) client/server running on OSX like I can with BlueZ on Linux.
On Linux, I simply open a socket, bind, listen & then accept for the server, & socket, bind, connect for the client (w/ the bind taking in the BT address of the device I want to use). Also, there's no pairing done.
I can't figure out how to configure my application to start listening for connections on a particular device (or if OSX only supports 1 BT adapater at a time, then how to listen for any incoming connections).
I also can't figure out how to configure my application to send to one BT device using a particular device (this is irrelevant if OSX only supports 1 at a time).
Also, does the OSX stack require pairing to have occured between 2 devices before it'll pass through l2cap?
Any language examples would be appreciated, although C/C++ would be preferred.
Thanks
In Mac OS X 10.5 there's an example (in /Developer/Examples/Bluetooth, titled RFCOMM_Open_SPP_Example) that shows connecting to and reading data from a bluetooth device (i've used it to read NMEA lines from a BT GPS receiver). See also: Leopard & Bluetooth RFCOMM channels
Unfortunately I can't find a copy of the example project anywhere.
It looks like the code samples have been replaced with: Developing Bluetooth Applications

Resources