3

Is there a way to obtain a MAC address with GNAT.Sockets?

I've read the .ads file several times and seen nothing that looks like it would yield a MAC address.

Ads here

Ignoreme
  • 193
  • 1
  • 2
  • 11

2 Answers2

2

While googling for your problem, I found a C solution here you could interface to. One advantage of this compared to calling system command is that you don't rely on parsing the output of the command and thus to its format. One drawback is that you have to use Interfacing annex of Ada but as it's standard, it's easy.

Hope this will help.

Frédéric Praca
  • 1,620
  • 15
  • 29
0

Get your local socket address with Get_Socket_Name and match that to the address of one of your network interfaces.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • I know how to get IP addresses, but the phrase "match that to the address of one of your network interfaces" explains nothing. – Ignoreme May 30 '12 at 15:59
  • `/sbin/ifconfig -a` on Unix, `ipconfig /all` on Windows? – Nikolai Fetissov May 30 '12 at 16:04
  • What do you need MAC addresses for anyway? – Nikolai Fetissov May 30 '12 at 16:05
  • writing a client that accepts messages through a socket from a webpage. For security reasons, I need to match the MAC of the Client to the MAC of the Server because IP's are more easily spoofed – Ignoreme May 30 '12 at 16:22
  • also, i don't think ipconfig /all shows the ip's of who the socket is connected to. – Ignoreme May 30 '12 at 16:26
  • maby netstat or something like that – Ignoreme May 30 '12 at 16:27
  • 2
    Hmm, sorry, but this is a waste of time. MAC addresses are easily spoofed too. This is best done at the system/network administration/security level. One easy solution is an SSH port forward from one machine to the other. – Nikolai Fetissov May 30 '12 at 16:30
  • `ipconfig /all` shows what addresses are assigned to network cards on the box. `netstat -a` shows the connected and listening sockets and their addresses. – Nikolai Fetissov May 30 '12 at 16:32
  • Nikolai is right. The MAC address field in a Ethernet packet is just data. A malicious client can as easily fill it in with your server's MAC address as they can fill the IP field in with your server's IP address. I even know some protocols that rely on this being trivial (they use RAW ethernet, and have a specific MAC address they expect clients to use). – T.E.D. May 30 '12 at 16:44
  • Well I knew it was just a field in the packet, but I figured the machine might throw out packets with it's own MAC if it didn't send them. I was trying to think of a simple way to validate data without having to write something complicated D:. – Ignoreme May 30 '12 at 16:55
  • @Kronos25 - Nope. In fact, if you are on a Windows box and have admin and a card with a decent Windows driver, you can go set your MAC to whatever you like. Also if someone is willing to do RAW sockets (which again on Windows just requires Admin), they can write all the IP and TCP/UDP headers themselves, and put in whatever values they want. – T.E.D. May 31 '12 at 16:26