Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ある日、突然ホスト名が “MacBookPro” になった話
Search
Yoshimasa Niwa
October 30, 2024
0
200
ある日、突然ホスト名が “MacBookPro” になった話
ある日、突然ホスト名が “MacBookPro” になった話
Yoshimasa Niwa
October 30, 2024
Tweet
Share
More Decks by Yoshimasa Niwa
See All by Yoshimasa Niwa
TextKit 2 時代の iOS のキーボードとテキスト入力と表示のすべて
niw
6
3.6k
Xcode が遅い! とにかく遅い!! 遅い Xcode をなんとかする方法
niw
1
7.5k
実践 iOS オープンソースプロジェクトの始め方
niw
5
3.3k
iOS のキーボードと文字入力のすべて
niw
14
3k
Getting started with making macOS utility app using private APIs
niw
3
2.4k
アプリの国際化の舞台裏
niw
11
7.4k
Lessons Learned
niw
6
4.9k
Getting Started with Scalding, Storm and Summingbird
niw
9
2.8k
Introducing Poxen
niw
4
620
Featured
See All Featured
Being A Developer After 40
akosma
87
590k
Designing for Performance
lara
604
68k
Visualization
eitanlees
146
15k
Documentation Writing (for coders)
carmenintech
66
4.5k
Side Projects
sachag
452
42k
Gamification - CAS2011
davidbonilla
80
5.1k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Designing for humans not robots
tammielis
250
25k
We Have a Design System, Now What?
morganepeng
51
7.3k
Bash Introduction
62gerente
608
210k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Typedesign – Prime Four
hannesfritz
40
2.4k
Transcript
͋Δɺಥવϗετ໊͕ “MacBookPro” ʹͳͬͨ @niw 10/30/2024 — Tokyo, Japan ΰϦϥ.vim #33
Yoshimasa Niwa @niw
Vim ϢʔβʔͰ͢!
͋Δɺಥવϗετ໊͕ “MacBookPro” ʹͳͬͯ͠·ͬͨ
None
ͳͥ?
None
System Configuration Parameters macOS ͷઃఆ scutil --get --set ͰҎԼͷ3ͭઃఆ͕Ͱ͖Δ
ComputerName LocalHostName HostName
System Configuration Parameters macOS ͷઃఆ ComputerName Λ௨ৗઃఆ͢Δ LocalHostName σϑΥϧτͰ ComputerName
HostName ௨ৗ ”” (ۭനจࣈྻ) ɻDNS ͷٯҾ͖Ͱܾఆɻ hostname(1) gethostname(3) ͷ͜ͷ HostName
ͭ·Γ DNS ٯҾ͖͕ “MacBookPro” ʹͳ͍ͬͯΔ!
Α͋͘Δϧʔλͷڍಈ DNS ͷٯҾ͖ొ Α͋͘Δϧʔλ DHCP Ͱ IPv4 ΞυϨεΛΓͭͭɺDNS ͷϓϩΩγͱΩϟογϡΛ͢Δɻ ͜ͷDNS
ϓϩΩγ͕ͨ·ʹٯҾ͖ొΛ͢ΔλΠϓͷͷ ͕͋Δɻ dnsmasq ͳͲ͕࣮ྫɻ
https://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
None
None
None
DHCP Ͱ “MacBookPro” ͱ ͍͏ϗετ໊Λཁٻ͍ͯ͠Δ?
DHCPREQUEST Option 12 DHCP Ͱϗετ໊Λࢦఆ͢Δ ࠓ࣌ͷ DHCP RFC 2131
Dynamic Host Con fi guration Protocol Ͱنఆ͞ΕΔ ॴҦαʔόʔɾΫϥΠΞϯτϞσϧͰɺΫϥΠΞϯτͷཁٻ ʹαʔόʔ͕ IP ΞυϨε DNS αʔόͷΞυϨεΛฦ͢ Δ
-------- ------- | | +-------------------------->| |<-------------------+ | INIT- | |
+-------------------->| INIT | | | REBOOT |DHCPNAK/ +---------->| |<---+ | | |Restart| | ------- | | -------- | DHCPNAK/ | | | | Discard offer | -/Send DHCPDISCOVER | -/Send DHCPREQUEST | | | | | | DHCPACK v | | ----------- | (not accept.)/ ----------- | | | | | Send DHCPDECLINE | | | | REBOOTING | | | | SELECTING |<----+ | | | | / | | |DHCPOFFER/ | ----------- | / ----------- | |Collect | | | / | | | replies | DHCPACK/ | / +----------------+ +-------+ | Record lease, set| | v Select offer/ | timers T1, T2 ------------ send DHCPREQUEST | | | +----->| | DHCPNAK, Lease expired/ | | | | REQUESTING | Halt network | DHCPOFFER/ | | | | Discard ------------ | | | | | | ----------- | | +--------+ DHCPACK/ | | | | Record lease, set -----| REBINDING | | | timers T1, T2 / | | | | | DHCPACK/ ----------- | | v Record lease, set ^ | +----------------> ------- /timers T1,T2 | | +----->| |<---+ | | | | BOUND |<---+ | | DHCPOFFER, DHCPACK, | | | T2 expires/ DHCPNAK/ DHCPNAK/Discard ------- | Broadcast Halt network | | | | DHCPREQUEST | +-------+ | DHCPACK/ | | T1 expires/ Record lease, set | | Send DHCPREQUEST timers T1, T2 | | to leasing server | | | | ---------- | | | | |------------+ | +->| RENEWING | | | |----------------------------+ ---------- Figure 5: State-transition diagram for DHCP clients https://datatracker.ietf.org/doc/html/rfc2131
DHCPREQUEST Option 12 DHCP Ͱϗετ໊Λࢦఆ͢Δ ΫϥΠΞϯτ DHCPREQUEST ΛૹΓɺαʔόʔ DHCPACK Ͱ
IPΞυϨεΛฦ͢ DHCPREQUEST ʹΦϓγϣϯ͕͋ΓɺRFC 1533 Ͱنఆ͞ ΕΔ Host Name Option (Code = 12) Ͱϗετ໊ΛࢦఆͰ͖Δ
None
“MacBookPro” ͕ Option 12 Ͱࢦఆ͞Ε͍ͯΔ!
͍Ζ͍Ζ࿙ΕͯΔ Wi-Fi ͷϓϥΠόγʔ Wi-Fi ΘΓͱઅૢͳͦ͘ͷΜʹ͋ΔͷΛͬͯ͠·͏ Wi-Fi Ͱ IPv4 ௨৴͕Ͱ͖Δͷ DHCP
͕͋Δ͔Β ΫϥΞϯτ DHCP ʹ͍Ζ͍ΖใΛͯ͠͠·ͬͯΔ ϗετ໊͕ʮ୭ʑͷPCʯͩͱɺOption 12 ʹ୭ʑͷ෦͕ ೖ͍ͬͯͨΓͯ͠ɺIPΞυϨε͔Βݸਓ͕ಛఆͰ͖ΔՄೳੑ ͋Δ
͍Ζ͍Ζ࿙ΕͯΔ Wi-FiͷϓϥΠόγʔ ࣮ macOS 15 ͔Β DHCP ΫϥΠΞϯτͷ࣮͕มΘͬͯ ͍Δɻ σϑΥϧτͰɺWi-Fi
ܦ༝ͷ DHCPREQUEST ͷϗετ໊ ৗʹσόΠεͷछྨʹͳΔɻྫ͑ɺMacBookPro ɺ MacBookAir
https://github.com/apple-oss-distributions/bootp/blob/ main/IPCon fi guration.bproj/dhcp.c#L473-L487
https://github.com/apple-oss-distributions/bootp/blob/ main/IPCon fi guration.bproj/ipcon fi gd.c#L5405-L5408
https://github.com/apple-oss-distributions/bootp/blob/main/bootplib/interfaces.c#L872-L880
#define LOCAL_ADMIN 0x2 return addr->addr[0] & LOCAL_ADMIN) != 0;
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ iPhone
Mac ͷ MAC ΞυϨεσϑΥϧτͰϥϯμϚΠζ ͞Ε͍ͯΔ MAC ΞυϨε 64-bit ͋ͬͯɺ࠷ॳͷ 32-bit ϕϯμʔ͝ ͱʹܾ·͍ͬͯΔ ͜ΕΛ OUIs (Organizationally Unique Identi fi ers) ͱ͍͏
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ ࠷ॳͷόΠτͷԼ͔Β2൪ͷϏοτ OUI
ͷҰ෦ OUI ϝʔΧʔ͝ͱʹൃߦ͞Ε͍ͯΔ ·͔͞ɺApple ಛఆͷ OUI ϨϯδΛશ෦͍࣋ͬͯΔ?
IEEE 802-2001
2nd LSB of 1st octet of OUI MACΞυϨεϥϯμϚΠθʔγϣϯ ͭ͡ɺOUI ͷ࠷ॳͷόΠτͷԼ2Ϗοτ༧͞Ε͍ͯΔ
Լ͔Β1Ϗοτ༻్͕ܾ·͍ͬͯΔ Լ͔Β2ϏοτΊ0ͱܾ·͍ͬͯΔ ͭ·Γɺਖ਼نͷOUIͰɺԼ͔Β2Ϗοτ͕1ʹͳΔ͜ͱͳ ͍
None
$ irb irb(main):001> "f6:06:3a:90:bc:fe".split(/:/) .map{|s| "%08b" % s.to_i(16)}.join(" ") =>
"11110110 00000110 00111010 10010000 10111100 11111110"
None
$ irb irb(main):001> "f0:00:00:00:00:00".split(/:/) .map{|s| "%08b" % s.to_i(16)}.join(" ") =>
"11110000 00000000 00000000 00000000 00000000 00000000"
ϗετ໊͕ “MacBookPro” ʹͳͬͨཧ༝ ·ͱΊ MACΞυϨεͷϥϯμϚΠθʔγϣϯͷख๏ͰMACΞυϨε ͷ࠷ॳͷΦΫςοτͷԼ͔Β2Ϗοτ͕1ʹͳΔ͜ͱͰɺ DHCPΫϥΠΞϯτ͕ϓϥΠϕʔτΞυϨεͱஅ͠ɺσό ΠεͷϞσϧ໊ΛDHCPREQUESTͷOption 12ʹϗετ໊ͱ͠ ͯࢦఆ͢Δ͜ͱͰɺDHCPαʔόͱ࿈ಈ͢ΔDNSαʔό͕ͦ
ͷϞσϧ໊ΛٯҾ͖ొͨ݁͠ՌɺDNSΫϥΠΞϯτͷٯҾ ͖ղܾͰϞσϧ໊͕ฦ͖ͬͯͨҝ